package insight.google.game.era.bo.policy.gamecard;

import insight.google.game.era.bo.GameActionLog;
import insight.google.game.era.bo.GameRoom;
import insight.google.game.era.bo.GameUser;
import insight.google.game.era.bo.Task;
import insight.google.game.era.bo.policy.AbstractPolicy;
import insight.google.game.era.bo.policy.PolicyCenter;
import insight.google.game.era.client.proxy.PlayerClientProxy;
import insight.google.game.era.client.proxy.PlayerClientProxyImpl;
import insight.google.game.era.mgr.GameLogManager;

import java.util.List;
import java.util.Map;

public class DefendPolicy extends AbstractPolicy {

    /**
	 * 
	 */
	private PlayerClientProxy playerClientProxy;

    @Override
    public boolean execute(GameUser original, GameUser[] targets, Map params) {
        // TODO Auto-generated method stub
        playerClientProxy = PlayerClientProxyImpl.getInstance();
      //started monirul for game log
    	GameRoom currentRoom = (GameRoom)original.getCurrentRoom();
    	GameLogManager gameLogManager = currentRoom.getGameLogManager();
    	//ended monirul for game log
        boolean rtnValue = false;
        PolicyCenter pCenter = PolicyCenter.getInstance();
        List<Task> taskList = currentRoom.getTaskList();
        int index = 0;
        for(Task task : taskList){
            String matchValue = (String)task.getMatchCardValue();
            String trgUser = task.getTargetUserName();
            if(matchValue.equals(PolicyCenter.CARD_TYPE_DEFEND)
                    && trgUser.equals(original.getName())){
            	currentRoom.removeTask(index);
                rtnValue = true;
                gameLogManager.addGameLog(new GameActionLog(original.getName() + " has played defend card "));
                break;
            }
            index++;
        }
//        currentRoom.setHangUser(null);
//        //set target user active
//        for(int i=0; i<targets.length; i++){
//            GameUser trgUser = targets[i];
//            //get js component id
//            String jsComponentId = (String)params.get("jsComponenetId");
//            //set target user active
////            playerClientProxy.setActive(trgUser.getScriptProxy(), jsComponenetId, true);
//            trgUser.setActive(true, jsComponentId);
//            
//        }
        return rtnValue;
    }

}
